import qs from 'qs';
export default {
    getReferer(ctx){
        let {client_ip,http_user_agent} = ctx.http_info;
        let program = "h5_client",user_agent = http_user_agent.toLowerCase();

        if(/MicroMessenger/i.test(user_agent)){
            program = "wx_client"
        }
        return program
    },
    getUrlParams(url){
        var obj = {},
            reg = /([^?=&#]+)=([^?=&#]+)/g;

        url.replace(reg, function() {
            let val = decodeURIComponent(arguments[2]);
            // if(/[\u4e00-\u9fa5]/.test(val)){
            //     val = encodeURIComponent(val)
            // }
            obj[arguments[1]] = val;
        });
        return obj
    },
    encodeParams(url){
        let params = this.getUrlParams(url);
        url  = url.split('?')[0];
        return url + '?'+ qs.stringify(params);
    }
    
}